﻿using Coater.Helper;
using Coater.UC;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using Coater.Enum;

namespace Coater
{
    public partial class FormFluidSetup : Form
    {
        public FormFluidSetup()
        {
            InitializeComponent();
        }

        private void btnOK_Click(object sender, EventArgs e)
        {
            List<NozzleInfo> nozzles = new();
            List<ucFluidSetup> liCons = new List<ucFluidSetup>();
            ComFunc.GetControl(this, ref liCons);
            foreach (var con in liCons)
            {
                nozzles.Add(con.GetData());
            }
            DeviceContext.Instance.SaveNozzleConfig(nozzles);
            DeviceContext.Instance.LoadNozzleConfig();
            this.DialogResult = DialogResult.OK;
        }

        private void btnCancel_Click(object sender, EventArgs e)
        {
            this.DialogResult = DialogResult.Cancel;
        }

        private void FormFluidSetup_Load(object sender, EventArgs e)
        {
            List<ucFluidSetup> liCons = new List<ucFluidSetup>();
            ComFunc.GetControl(this, ref liCons);
            foreach (var con in liCons)
            {
                var nozzle = DeviceContext.Instance.Nozzles.FirstOrDefault(x => x.Nozzle == con.Nozzle);
                if (nozzle != null)
                {
                    con.ShowData(nozzle);
                }
            }
            ucNozzle6.Visible = DeviceContext.Instance.Config.Coater.EnableBacksideNozzle6;
        }
    }
}
